package com.xxmw.transaction.valid;

import org.apache.commons.lang.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;

/**
 * 自定义注解验证
 * @since  2020/2/28 14:59
 * @author luowenliang
 */
public class DecimalGtValidatorForString implements ConstraintValidator<DecimalGt, String> {

	private DecimalGt annotation;

	@Override
	public void initialize(DecimalGt constraintAnnotation) {
		this.annotation = constraintAnnotation;
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (StringUtils.isNotBlank(value)) {
			BigDecimal input = new BigDecimal(value);
			BigDecimal borderValue = new BigDecimal(annotation.value());
			return input.compareTo(borderValue) == 1;
		}
		return false;
	}
}
